﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using AspNetCs.Bll;
using AspNetCs.Common;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.SaleNumber_Enum;
using AspNetCs.Enumerations.Channel_Enum;

public partial class AjaxXml_ValidateAncestralHallId : BasePage
{
    AncestralHallBLL bll = new AncestralHallBLL();
    protected SaleNumber SaleBll = new SaleNumber();
    protected string NewNumber = "-1";
    protected int Result = 0;//可以使用
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request["NewNumber"]))
        {
            NewNumber = Request["NewNumber"].ToString().ToLower().Trim();
        }
        if (!StringHelper.Str_IsInt(NewNumber, out NewNumber))
        {
            Response.Write(-3);
            Response.End();
        }

        DataTable dt = SaleBll.GetNetMuIdDataTable(" and  Number='" + NewNumber + "'");
        if (dt.Rows.Count > 0)
        {
            Result = -1;//表中存在该宗祠编号,但不一定是该用户的
            foreach (DataRow dr in dt.Rows)
            {
                if (StringHelper.isNumber_int(dr["UserId"].ToString()) == Base_GetLoginInfo.GetUserID && StringHelper.isNumber_int(dr["UserState"].ToString()) == (int)UserState_Enum.Yes && StringHelper.isNumber_int(dr["SaleType"].ToString()) == (int)Channel_Type.clan)
                {
                    Result = 1;//表示可以使用
                    break;
                }
            }
        }
        if (bll.IsExistAncestralHallId(NewNumber))
        {
            Result = -2;//表示该宗祠编号已经被使用
        }

        Response.Write(Result);
        Response.End();
    }
}
